Public Class verDesglose

    Private idE As Integer
    Private idG As Integer
    Private nombre As String
    Private apellidos As String
    Private activo As Integer
    Private promedios As ArrayList
    Private gestor As capaNegocios.Gestor = gestor.instanciar

    Public Sub cargarDatos(ByVal pidE As Integer, ByVal pidG As Integer, ByVal pnombre As String, ByVal papellidos As String, ByVal pactivo As Integer)
        Me.idE = pidE
        Me.idG = pidG
        Me.nombre = pnombre
        Me.apellidos = papellidos
        Me.activo = pactivo
    End Sub

    Private Sub cargarLista()
        Dim datos As DataTable
        With gestor
            Me.listaDesglose.Refresh()
            datos = .mostrarDesgloseEstudiante(Me.idG, Me.idE)
            listaDesglose.DataSource = datos
            If datos.Rows.Count > 0 Then
                Me.generarReporte.Enabled = True
            Else
                Me.generarReporte.Enabled = False
            End If
        End With
        If datos.Rows.Count > 0 Then
            Me.TextNota.Enabled = True
        End If
    End Sub

    Private Sub asignarNota(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextNota.KeyDown
        Dim fila As Integer
        Try
            If e.KeyCode = Keys.Enter Then
                If MessageBox.Show("Desea modificar la nota?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) = Windows.Forms.DialogResult.Yes Then
                    Dim nota As String = CType(Me.TextNota.Text, String)
                    fila = listaDesglose.CurrentRow.Index
                    Dim idR As Integer = CInt(listaDesglose(2, fila).Value)
                    gestor.modificarNota(Me.idG, Me.idE, idR, nota)
                    Me.cargarLista()
                    Me.cargarCampos()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub mostrarNota(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listaDesglose.SelectionChanged
        If listaDesglose.CurrentRow IsNot Nothing Then
            Dim fila As Integer
            fila = listaDesglose.CurrentRow.Index
            'Dim nota As String = listaDesglose(1, fila).Value
            Me.TextNota.Text = CInt(listaDesglose(1, fila).Value) 'nota
        End If
    End Sub

    Private Sub cargarCampos()
        Me.TextEstudiante.Text = nombre & " " & apellidos
        promedios = gestor.mostrarPromedioEstudiante(Me.idG, Me.idE)
        Dim a, b, c, d, e, f As ArrayList
        a = promedios.Item(0)
        b = promedios.Item(1)
        c = promedios.Item(2)
        d = promedios.Item(3)
        e = promedios.Item(4)
        f = promedios.Item(5)
        Me.TextBox1.Text = a.Item(0) & " %  / " & a.Item(1) & " % "
        Me.TextBox2.Text = b.Item(0) & " %  / " & b.Item(1) & " % "
        Me.TextBox3.Text = c.Item(0) & " %  / " & c.Item(1) & " % "
        Me.TextBox4.Text = d.Item(0) & " %  / " & d.Item(1) & " % "
        Me.TextBox5.Text = e.Item(0) & " %  / " & e.Item(1) & " % "
        Me.TextBox6.Text = f.Item(0) & " %  / " & f.Item(1) & " % "
    End Sub

    Private Sub cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cerrar.Click
        Me.Close()
    End Sub

    Private Sub generarReporte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles generarReporte.Click
        Me.generarReporte.Cursor = Cursors.AppStarting
        Dim visor As New VisorReporte
        Dim da, es, dc As New DataTable
        Dim valor As Integer
        da = gestor.mostrarDesgloseEstudiante(Me.idG, Me.idE)
        es = gestor.darEstudiante(Me.idG, Me.idE)
        valor = gestor.darActividad(Me.idG)
        If (valor = 1) Then
            dc = gestor.obtenerElGrupoActivo(Me.idG)
        Else
            dc = gestor.obtenerElGrupoInactivo(Me.idG)
        End If
        visor.llenar(da, es, dc)
        visor.Show()
        Me.generarReporte.Cursor = Cursors.Arrow
    End Sub

    Private Sub verDesglose_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.cargarLista()
        Me.cargarCampos()
        If (Me.activo = 0) Then
            Me.TextNota.Visible = False
            'Me.generarReporte.Visible = False
        End If
    End Sub
End Class